#include<stdio.h>
#include<math.h>

int main()
{
    double a[3][3] = {{4, -2, 4}, { -2, 17, 10}, { -4, 10, 9}}, b[3] = {10, 3, 7}, x[3], M, temp;
    int k, i, j, m;
    for (k = 0; k < 2; k++)                            //在相应的列中选主元//
    {
        m = k;
        for (i = k + 1; i < 3; i++)
        {
            if (fabs(a[i][k]) > fabs(a[m][k]))
                m = i;
        }
        if (a[m][k] == 0)
        {
            printf("ERROR");
            return 0;
        }
        else                                           //两行进行比较交换两行//
        {
            for (j = 0; j < 3; j++)
            {
                temp = a[k][j];
                a[k][j] = a[m][j];
                a[m][j] = temp;
            }
            temp = b[m];
            b[m] = b[k];
            b[k] = temp;
        }
        for (i = k + 1; i <= 2; i++)
        {
            M = a[i][k] / a[k][k];
            b[i] = b[i] - M * b[k];
            for (j = 0; j < 3; j++)
            {
                a[i][j] = a[i][j] - M * a[k][j];
            }
        }
    }
    x[2] = b[2] / a[2][2];
    x[1] = (b[1] - x[2] * a[1][2]) / a[1][1];
    x[0] = (b[0] - x[2] * a[0][2] - x[1] * a[0][1]) / a[0][0];
    printf("x1 = %.10f\nx2 = %.10f\nx3 = %.10f\n", x[0], x[1], x[2]);
    return 0;
}
